package com.example.HaiDLaobackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.HaiDLaobackend.entity.OrderEntity;
import com.example.HaiDLaobackend.mapper.OrderMapper;
import com.example.HaiDLaobackend.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> implements OrderService {
    @Override
    public Map<String, Long> summaryByStatus(Long userId) {
        Map<String, Long> summary = new HashMap<>();
        if (userId == null) {
            summary.put("all", 0L);
            summary.put("pendingPay", 0L);
            summary.put("pendingShip", 0L);
            summary.put("pendingReceive", 0L);
            summary.put("pendingComment", 0L);
            return summary;
        }
        summary.put("all", count(new LambdaQueryWrapper<OrderEntity>().eq(OrderEntity::getUserId, userId)));
        summary.put("pendingPay", count(new LambdaQueryWrapper<OrderEntity>().eq(OrderEntity::getUserId, userId).eq(OrderEntity::getStatus, "CREATED")));
        summary.put("pendingShip", count(new LambdaQueryWrapper<OrderEntity>().eq(OrderEntity::getUserId, userId).eq(OrderEntity::getStatus, "PAID")));
        summary.put("pendingReceive", count(new LambdaQueryWrapper<OrderEntity>().eq(OrderEntity::getUserId, userId).eq(OrderEntity::getStatus, "SHIPPED")));
        summary.put("pendingComment", count(new LambdaQueryWrapper<OrderEntity>().eq(OrderEntity::getUserId, userId).eq(OrderEntity::getStatus, "COMPLETED")));
        return summary;
    }
}


